package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.domain.Attention;
import cn.wolfcode.trip.base.service.IAttentionService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/attentions")
public class AttentionController {
    @Autowired
    private IAttentionService attentionService;

    //点击关注
    @PostMapping
    @ResponseBody
    public Object save(Attention attention){
        JSONResult result = new JSONResult();
        try {
            attentionService.save(attention);
            result.setData(attention.getId());
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    //查询是否关注
    @GetMapping
    @ResponseBody
    public Object get(Long currentUserId, Long attentionUserId){
        Attention attention = attentionService.get(currentUserId, attentionUserId);
        return attention;
    }

    //取消关注
    @DeleteMapping
    @ResponseBody
    public Object delete(Long aid){
        JSONResult result = new JSONResult();
        try {
            attentionService.delete(aid);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    //粉丝数
    @GetMapping("/{attentionUserId}/fans")
    @ResponseBody
    public Object fans(@PathVariable Long attentionUserId){
        return attentionService.fans(attentionUserId);
    }

    //被关注数
    @GetMapping("/{currentUserId}/attentionNum")
    @ResponseBody
    public Object attentionNum(@PathVariable Long currentUserId){
        return attentionService.attentionNum(currentUserId);
    }

}
